package cn.fz.redisdemo01.web;

import cn.fz.redisdemo01.domain.dto.UserDto;
import cn.fz.redisdemo01.service.User2Service;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user2")
@RequiredArgsConstructor
public class User2Controller {
    private final User2Service user2Service;

    /**
     * 当调用 getUserById 时，缓存数据会存储在默认的缓存区域，数据会在 5 分钟后过期。
     * @param id
     * @return
     */
    @GetMapping("/getCustom")
    public UserDto getCustom(@RequestParam("id") Long id) {
        return user2Service.getUserById(id);
    }
}
